﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entitty;

namespace ClassLibrary.DAO
{
    public class TblContactDAO
    {
         private DBService _db = null;

         public TblContactDAO(string ConnectionString)
         {
            _db = new DBService(ConnectionString);
         }

         public DataTable Insert(TblContact contact, int Mode)
         {
             DataTable dt = null;
             try
             {

                 dt = _db.ExeSP_DataTable("sp_TblContact_InsUp",
                     new string[] { "@id", "@Phone", "@Email", "@yahoo", "@mode" },
                     new object[] { contact.Id, contact.Phone, contact.Email, contact.Yahoo, Mode },
                     CommandType.StoredProcedure);

             }
             catch (Exception ex)
             {
                 throw ex;
             }
             return dt;
         }

         public TblContact GetContactById(int id)
         {
             TblContact contact = new TblContact();
             try
             {
                 DataTable dt = null;
                 dt = _db.ExeSP_DataTable("select * from TblContact where id = @id",
                     new string[] { "@id" },
                     new object[] { id }, CommandType.Text);
                 foreach (DataRow dr in dt.Rows)
                 {
                     contact.Id = id;
                     contact.Phone = dr["Phone"].ToString();
                     contact.Email = dr["Email"].ToString();
                     contact.Yahoo = dr["yahoo"].ToString();

                 }
             }
             catch (Exception ex)
             {
                 throw ex;
             }
             return contact;
         }

         public DataTable GetAll()
         {
             DataTable dt = null;
             dt = _db.ExeSP_DataTable("select * from TblContact", false, CommandType.Text);
             return dt;
         }
    }
}
